local conns = {}

function on_init(id)
    print('[lua] on_init ' .. id)

    sunnet.listen(8002, id)
end

function on_accept_msg(fd)
    print('[lua] on accept msg ' .. fd)
    conns[fd] = true
end

function on_socket_date(fd, msg)
    -- 打印的消息中多一个换行的原因是 发送的时候带一个 \n, 而 print 也会打印一个.
    print('[lua] on_socket_date' .. msg)
    for fd in pairs(conns) do
        sunnet.write(fd, msg)
    end
end

function on_socket_close(fd)
    print('[lua] on socket close ' .. fd)
end
